﻿using System.Windows;
using System.Windows.Controls;
using eProject.ViewModel;

namespace eProject.View
{
    /// <summary>
    /// Interaction logic for CreateTaskDialog.xaml
    /// </summary>
    public partial class CreateTaskDialog
    {
        public string TaskName { get; set; }
        public string TaskDescription { get; set; }
        public long TaskDuration { get; set; }

        public CreateTaskDialog(CommonManager manager, TaskViewModel task) : this(manager)
        {
            Title = Properties.Resources.EditTaskDialogHeader;
            TaskName = task.Name;
            TaskDescription = task.Description;
            TaskDuration = task.Duration;
            rule1.CurrentValue = task.Name;
        }

        public CreateTaskDialog(CommonManager manager)
        {
            InitializeComponent();
            Title = Properties.Resources.CreateTaskDialogHeader;
            DataContext = this;            
            TaskName = "";
            TaskDescription = "";
            TaskDuration = 0;

            Loaded += delegate
                          {
                              var name = nameTextBox.GetBindingExpression(TextBox.TextProperty);
                              var descr = descriptionTextBox.GetBindingExpression(TextBox.TextProperty);
                              var dur = durationTextBox.GetBindingExpression(TextBox.TextProperty);

                              if (name != null) name.UpdateSource();
                              if (descr != null) descr.UpdateSource();
                              if (dur != null) dur.UpdateSource();
                          };
            rule1.Enumerable = manager.Tasks;
            rule1.Converter = t => t.Name;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
